package com.weijia;

import javax.swing.*;
import java.awt.*;

public class TypingGamePlus extends JFrame {
    // 难度枚举，供 GameManager 使用
    public enum Difficulty {
        EASY(2000, 1, 2),
        NORMAL(1500, 2, 3),
        HARD(1000, 3, 5);

        private final int wordSpawnInterval;
        private final int minSpeed;
        private final int maxSpeed;

        Difficulty(int interval, int minSpeed, int maxSpeed) {
            this.wordSpawnInterval = interval;
            this.minSpeed = minSpeed;
            this.maxSpeed = maxSpeed;
        }

        public int getWordSpawnInterval() {
            return wordSpawnInterval;
        }
        public int getMinSpeed() {
            return minSpeed;
        }
        public int getMaxSpeed() {
            return maxSpeed;
        }
    }

    private GamePanel gamePanel;
    private ControlPanel controlPanel;
    private PauseOverlay pauseOverlay;
    private GameManager gameManager;

    public TypingGamePlus() {
        super("TypingGamePlus");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(1200, 800);
        setLocationRelativeTo(null);
        setResizable(false);

        // 初始化 UI 组件
        gamePanel = new GamePanel();
        controlPanel = new ControlPanel();
        pauseOverlay = new PauseOverlay();
        gameManager = new GameManager(gamePanel, controlPanel, pauseOverlay, this);

        // 让 UI 组件持有 gameManager 引用（便于事件回调）
        gamePanel.setGameManager(gameManager);
        controlPanel.setGameManager(gameManager);
        pauseOverlay.setGameManager(gameManager);

        // 叠加暂停层
        gamePanel.setLayout(new OverlayLayout(gamePanel));
        gamePanel.add(pauseOverlay);
        pauseOverlay.setVisible(false);

        // 布局
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, gamePanel, controlPanel);
        splitPane.setDividerLocation(800);
        splitPane.setDividerSize(5);
        add(splitPane);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            TypingGamePlus game = new TypingGamePlus();
            game.setVisible(true);
        });
    }
}

